package com.gzck.gzck_verson2.controller;


import com.gzck.gzck_verson2.pojo.GProjectUser;
import com.gzck.gzck_verson2.service.IGProjectUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户和工程中间表 前端控制器
 * </p>
 *
 * @author 任永辉
 * @since 2024-01-06
 */
@RestController
@RequestMapping("/g-project-user")
@CrossOrigin(origins = "*")
public class GProjectUserController {

    @Autowired
    private IGProjectUserService projectUserService;

    // 添加用户和工程关系
    @PostMapping("/add")
    public boolean addProjectUser(@RequestBody GProjectUser projectUser) {
        return projectUserService.save(projectUser);
    }

    // 删除用户和工程关系
    @DeleteMapping("/delete/{id}")
    public boolean deleteProjectUser(@PathVariable Long id) {
        return projectUserService.removeById(id);
    }

    // 更新用户和工程关系信息
    @PutMapping("/update")
    public boolean updateProjectUser(@RequestBody GProjectUser projectUser) {
        return projectUserService.updateById(projectUser);
    }

    // 查询单个用户和工程关系信息
    @GetMapping("/{id}")
    public GProjectUser getProjectUser(@PathVariable Long id) {
        return projectUserService.getById(id);
    }

    // 查询所有用户和工程关系信息
    @GetMapping("/all")
    public List<GProjectUser> getAllProjectUsers() {
        return projectUserService.list();
    }
}
